<template>
  <div id="approachList">
    <Filters
      block
      :form="searchForm"
      :filterData="filterData"
      @confirm="changePage(1)"
    />
    <div class="container">
      <DataTable
        rowKey="phid"
        :btns="btns"
        :tableData="Data"
        :tableColumn="tableColumn"
        :pageConfig="pageConfig"
        @refresh="getList"
      />
    </div>
<!--    <CommonDialog :rows="rows" :form="form" title="作废原因" :visible="formVisible" @hideDialog="hideFormVisible" @confirm="confirmHandle()"/>-->
  </div>
</template>
<script lang='ts'>
import { Confirm } from '@/decorator';
import { Component, Watch, Vue } from 'vue-property-decorator';

@Component
export default class approachInvoiceList extends Vue {
  formVisible:any = false
  searchForm: any = {
    billdate: [],
    markTime: [],
    billcode: '',
    billstatus: '',
    dealstatus: ''
  }
  btns: any[] = [
    {
      label: '新增进场单',
      icon: 'add',
      callback: () => this.$router.push('/wasteManage/approach/edit')
    }
  ];
  get filterData () {
    return {
      billdate: {
        label: '单据日期',
        type: 'daterange',
        template: {
          clearable: true
        }
      },
      billcode: {
        label: '进场单编号',
        type: 'input',
        template: {
          placeholder: '请输入进场单编号',
          clearable: true
        }
      },
      billstatus: {
        label: '单据状态',
        type: 'select',
        width: 200,
        template: {
          placeholder: '请选择状态',
          clearable: true,
          filterable: true,
          options: this.$enums.acceptanceList.billOptions
        }
      }
    }
  }
  Data: any[] = [];
  tableColumn: any = {
    billcode: {
      label: '进场单编号'
    },
    billdate: {
      label: '单据日期'
    },
    billStatusName: {
      label: '单据状态',
      width: 100
    },
    orgName: {
      label: '组织'
    },
    complanyName: {
      label: '区域'
    },
    projectName: {
      label: '项目'
    },
    registerName: {
      label: '申请人',
      width: 100
    },
    action: {
      label: '操作',
      width: 150,
      template: [
        {
          tag: 'router-link',
          text: '详情',
          query: {
            _alias: 'detail',
            phid: ''
          },
          path: '/wasteManage/approach/detail'
        },
        {
          tag: 'router-link',
          text: '编辑',
          query: {
            _alias: 'edit',
            phid: ''
          },
          path: '/wasteManage/approach/edit'
        },
        {
          tag: 'a',
          text: '删除',
          callback: this.deleteCheck
        }
      ]
    }
  };
  pageConfig: any = {
    current: 1,
    total: 10,
    pageSize: 10,
    onChange: this.changePage
  };
  form: any = {
    cancelReason: '',
    phid: ''
  };
  // 删除
  deleteCheck (val: any) {
    let params = {
      phid: val.phid
    }
    this.$confirm({
      title: '提示',
      content: '是否确定删除' + val.billcode + '?',
      onOk: () => {
        this.$api.approachDeleteFetch(params).then((res) => {
          this.$message.success('删除成功')
          this.getList()
        }).catch()
      },
      onCancel: () => {}
    })
  }

  get getSearchForm () {
    let {billdate, markTime} = this.searchForm
    let [makeStartTime, makeEndTime] = markTime
    let [checkStartTime, checkEndTime] = billdate
    return {
      ...this.searchForm,
      markTime: undefined,
      billdate: undefined,
      makeStartTime,
      makeEndTime,
      checkStartTime,
      checkEndTime
    }
  }

  init () {
    this.getList();
  }
  getList () {
    let data = {
      ...this.getSearchForm,
      page: this.pageConfig.current,
      size: this.pageConfig.pageSize
    };
    this.$api.approachListFetch(data).then((res: any) => {
      res.data.records.map((item:any) => {
        if (item.isContract === 1) {
          item.isContract = true
        } else {
          item.isContract = false
        }
      })
      this.Data = res.data.records;
      this.pageConfig.total = res.data.total;
      if (!this.Data.length && this.pageConfig.current > 1) {
        --this.pageConfig.current;
        this.getList();
      }
    });
  }
  hideFormVisible () {
    this.formVisible = false
    this.form.cancelReason = ''
    this.form.phid = ''
  }
  changePage (val: number) {
    this.pageConfig.current = val;
    this.getList();
  }
  @Confirm('', ({ checkSn }: any) => {
    return new Promise((resolve, reject) => {
      resolve({ content: `确定撤回[${checkSn}]验收单吗?`, width: 550 })
    })
  })
  handleCancel ({ phid: id }: any) {
    this.$api.checkWithdrawPortFetch({ id, checkAcceptStatus: 'chehui' }).then(() => {
      this.$message.success('撤回成功')
      this.getList()
    })
  }
  @Confirm('', ({ checkSn }: any) => {
    return new Promise((resolve, reject) => {
      resolve({ content: `确定把[${checkSn}]的验收单推送NC吗?`, width: 550 })
    })
  })
  handlePush ({ phid: id }: any) {
    this.$api.checkWithdrawPortFetch({ id, checkAcceptStatus: 'nc' }).then(() => {
      this.$message.success('推送成功')
      this.getList()
    })
  }
  // 显示输入框
  showFormVisible (val:any) {
    console.log(val)
    this.formVisible = true
    this.form.phid = val.phid
  }
  // 点击确定作废
  confirmHandle () {
    this.$api.cancelCheckCancelCheckFetch(this.form).then(res => {
      if (res.code === 0) {
        this.$message.success('操作成功')
        this.getList()
        this.hideFormVisible()
      }
    }).catch()
  }
}
</script>
<style lang='scss' scoped>
</style>
